package com.cardbaobao.cardbabyclient.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.cardbaobao.cardbabyclient.R;
import com.cardbaobao.cardbabyclient.buried.Self;
import com.cardbaobao.cardbabyclient.buried.SelfUtils;
import com.cardbaobao.cardbabyclient.ui.activity.CreditDetailActivity;
import com.cardbaobao.cardbabyclient.ui.activity.base.BaseActivity;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerAdapter;
import com.cardbaobao.cardbabyclient.ui.adapter.base.CommonRecyclerHolder;
import com.cardbaobao.cardbabyclient.model.SpeedCard;
import com.cardbaobao.cardbabyclient.utils.DensityUtil;
import com.cardbaobao.cardbabyclient.utils.ImageLoaderUtil;
import com.cardbaobao.cardbabyclient.utils.URLUtil;

/**
 * Description:
 * Created by FHW
 * on 2017/6/13
 */

public class SpeedCardRcAdapter extends CommonRecyclerAdapter<SpeedCard.SpeedCardListBean> {
    private long enterTime;
    private String currentPageId;
    private String prePageId;
    public SpeedCardRcAdapter(Context context) {
        super(context, null, R.layout.item_high_privilege_speed_card);
    }

    public void setBuriedInfo(long enterTime, String currentPageId, String prePageId){
        this.enterTime=enterTime;
        this.currentPageId=currentPageId;
        this.prePageId=prePageId;
    }

    @Override
    public void convert(final CommonRecyclerHolder holder, final SpeedCard.SpeedCardListBean item) {
        if(holder.getAdapterPosition()==0){
            ((ViewGroup.MarginLayoutParams)holder.itemView.getLayoutParams()).topMargin=
                    DensityUtil.dp2px(5);
        }
        ImageView ivLevel = holder.getView(R.id.iv_level);
        switch (holder.position) {
            case 0:
                ivLevel.setImageResource(R.mipmap.icon_gold_medal);
                ivLevel.setVisibility(View.VISIBLE);
                break;
            case 1:
                ivLevel.setImageResource(R.mipmap.icon_silver_medal);
                ivLevel.setVisibility(View.VISIBLE);
                break;
            case 2:
                ivLevel.setImageResource(R.mipmap.icon_bronze_medal);
                ivLevel.setVisibility(View.VISIBLE);
                break;
            default:
                ivLevel.setVisibility(View.GONE);
                break;
        }
        holder.setTextViewText(R.id.tv_title, item.getName());
        if (item.getFeature_3g() != null) {
            holder.setTextViewText(R.id.tv_discount_top, "· " + item.getFeature_3g());
        }
//        holder.setTextViewText(R.id.tv_name,"· 生日当天5倍分");
        holder.setTextViewText(R.id.tv_apply_count, item.getApply_count() + "");

        ImageLoaderUtil.displayImage(URLUtil.CBB_IMG_URL + item.getImage(), (ImageView) holder.getView(R.id.iv_pic), 12);

        holder.getView(R.id.rl_root).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SelfUtils.buriedClickData(Self.Action.app_click_speed_card_item,
                        Self.Action.app_click_speed_card_item_des,
                        enterTime,
                        currentPageId,
                        prePageId);
                Intent mIntent = new Intent();
//                mIntent.setClass(mContext, CreditDetailActivity.class);
                mIntent.setClass(mContext, CreditDetailActivity.class);
                mIntent.putExtra(CreditDetailActivity.CARD_ID_S,
                        item.getId() + "");
                mIntent.putExtra(CreditDetailActivity.SERIES_CARD_ID_S,
                        item.getId() + "");
                mIntent.putExtra(CreditDetailActivity.CARD_NAME_S,
                        item.getName());
                mIntent.putExtra(CreditDetailActivity.FROM_PAGE_S,
                        mContext.getString(R.string.text_speed_credit));
                mIntent.putExtra(BaseActivity.PRE_PAGE_ID_S,
                        currentPageId);
                mContext.startActivity(mIntent);
            }
        });

    }

}
